from pyecharts.charts import Map
from pyecharts import options
from pyecharts.options import VisualMapOpts

# 创建地图对象
map = Map(init_opts=options.InitOpts(width="1250px", height="600px"))
# 准备数据
data = [
    ("北京市", 199),
    ("上海市", 599),
    ("深圳市", 799),
    ("山东省", 599),
    ("湖北省", 299),
    ("广东省", 99)
]
# 构建地图
map.add("测试地图",data,"china",)
# 全局配置项
map.set_global_opts(
    visualmap_opts=VisualMapOpts(
        is_show=True,
        is_piecewise=True,
        pieces=[
            {"min": 1, "max": 9, "label": "1-9", "color": "#80f581"},
            {"min": 10, "max": 99, "label": "10-99", "color": "#23b10b"},
            {"min": 100, "max": 999, "label": "100-999", "color": "#8fb10b"},
            {"min": 1000, "max": 9999, "label": "1000-9999", "color": "#f2ef40"},
            {"min": 10000, "max": 10001, "label": "一万及以上", "color": "#f2ba40"}
        ]
    )
)
# 生成地图文件
map.render("china_map_demo.html")
